﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.UI;


public static partial class I18N
{
	
	public static void ClearCache()
    {
		//txtLanguageMap.Clear();
		//DataConfigLanguage.Instance.Init();
	}

	public static string GetText(string keyid, string defaulttxt = "")
	{
		//ConfigLanguageType _type = configLanguagetype;// (ConfigLanguageType)Enum.Parse(typeof(ConfigLanguageType), Language.ToString());
		//if (txtLanguageMap.ContainsKey(keyid)&& txtLanguageMap[keyid].ContainsKey(configLanguagetype))
		//{
		//	return txtLanguageMap[keyid][_type];
		//}
  //      try
  //      {
		//	foreach (var p in DataConfigLanguage.Instance.dDataObj)
		//	{
		//		if(p.Key.ToString() == keyid)
		//		{
		//			string txt = DataConfigLanguage.Instance.GetContentByKeyAndType(p.Key, _type);

		//			if (txtLanguageMap.ContainsKey(keyid))
		//			{
		//				txtLanguageMap[keyid].Add(_type, txt);
		//			}
		//			else
		//			{
		//				Dictionary<ConfigLanguageType, string> keyValuePairs = new Dictionary<ConfigLanguageType, string>();
		//				keyValuePairs.Add(_type, txt);
		//				txtLanguageMap.Add(keyid, keyValuePairs);
		//			}

		//			return txtLanguageMap[keyid][_type];
		//		}
		//	}
		//}
  //      catch(Exception ex)
  //      {
		//	Debug.LogError(ex.Message);
  //      }

		return  defaulttxt;
	}

	/// <summary>
	/// 获取分割字符
	/// </summary>
    public static string GetSeparateSubString(string txtString, int charNumber) //charNumber为要截取的每段的长度
    {
        StringBuilder arrlist = new StringBuilder();
        string tempStr = txtString;
        for (int i = 0; i < tempStr.Length; i += charNumber)//首先判断字符串的长度，循环截取，进去循环后首先判断字符串是否大于每段的长度
        {
            if ((tempStr.Length - i) > charNumber)//如果是，就截取
            {
                arrlist.AppendLine(tempStr.Substring(i, charNumber));
            }
            else
            {
                arrlist.Append(tempStr.Substring(i));//如果不是，就截取最后剩下的那部分
            }
        }
        return arrlist.ToString();
    }

    public static Sprite GetSprite(string keyid, string defaulttxt)
	{
		return null;
	}

	/// <summary>
	/// 通过查找要数据的后缀字段合并为能够匹配各语言的新字段
	/// </summary>
	/// <param name="suffixes">约定格式：语言类型+翻译字段的后缀：ZhChsName,EnName ... </param>
	/// <returns></returns>
	public static string CombineText(string suffixes)
	{
		string label = Language.ToString() + suffixes;
		return label;
	}

}


